function LinkSelecter(id_father, id_child)
{
	this.father = id_father;
	this.child = id_child;
	this.opciones = new Array();
	this.dependencias = new Array();
	this.addOption = addOption;
	this.selected = selected;
	this.addDependency = addDependency;
	this.select = select;
}

function addOption(id, value)
{
	this.opciones[id] = value;
	this.dependencias[id] = new Array();
}

function selected()
{
	var tag = document.getElementById(this.father);
	var indice = tag.options[tag.selectedIndex].value;
	var tag2 = document.getElementById(this.child);
	var length = 0;
	for(i in this.dependencias[indice])
	{
		length++;
	}
	tag2.options.length = length;
	var j = 0;
	for(i in this.dependencias[indice])
	{
		tag2.options[j].value = i;
		tag2.options[j].text = this.dependencias[indice][i];
		j++;
	}
	if(tag2.onchange)
		tag2.onchange();
}

function addDependency(id_father, id_child, value)
{
	this.dependencias[id_father][id_child] = htmlEntityDecode(value);
}

function htmlEntityDecode(value)
{
	var ta = document.createElement("textarea");
	ta.innerHTML = value;
	return ta.value;
}

function select(value, father)
{
	var id = (father)? this.father: this.child;
	var tag = document.getElementById(id);
	var indice = 0;
	for(var i = 0; i < tag.options.length; i++)
		if(tag.options[i].value == value)
			break;
	tag.selectedIndex = i;
	if(father)
		this.selected();
}
